;(function () {
  new Vue({
    el: '#place-config',
    data: {
      newList: [],
      data: []
    },
    methods: {
      newAdd: function () {
        if (this.newList.length) {
          hl.toast('请先保存，在新增')
          return
        }
        this.newList.push({
          name: null,
          valid: 'Y'
        })
      },
      getList: function () {
        var self = this;
        hlhttp.get({
          url: 'configure/dict',
		      data: {module_code: 'ZHSH',config_name: 'ZS_INDUSTRY_TYPE'},
          success: function (res) {
            res.map(function (item) {
              item.flag = false;
            })
            self.data = res;
          }
        })
      },
      postAdd: function () {
        var self = this;
        if (!self.newList[0].name) {
          hl.toast('不能为空')
          return
        }
        if (!self.newList[0].name.replace(/(^\s*)|(\s*$)/g, "")) {
          hl.toast('不能为空')
          return
        }
        hlhttp.post({
          url: 'configure/industry/dict',
          data: {dict_name: self.newList[0].name},
          success: function (res) {
            hl.toast('新增成功')
            self.getList();
            self.newList = [];
          }
        })
      },
      delSlel: function (item) {
        var self = this;
        hllayer.confirm1('确认删除当条场地信息？', function() {
          hlhttp.delete({
            url: 'configure/industry/dict?dict_code='+item.dictCode,
            // data: {id: id},
            success: function (res) {
              hl.toast('删除成功')
              self.getList();
            }
          })
        })
      },
      editshow: function (i) {
        this.data[i].flag = true;
      },
      edithidePut: function (i) {
        var self = this;
        hlhttp.put({
          url: 'configure/industry/dict',
          data: {dict_name: self.data[i].dictName, dict_code: self.data[i].dictCode},
          success: function (res) {
            hl.toast('编辑成功')
            self.getList();
          }
        })
      },
      validopen: function (item) {
        let s = item.status == 'Y' ? 'N' : 'Y';
        var self = this;
        hlhttp.put({
          url: 'configure/industry/dict/_valid',
          data: {dict_code: item.dictCode, dict_name: item.dictName, opt: s},
          success: function (res) {
            hl.toast('操作成功')
            self.getList();
          }
        })
      },
      delListNew: function () {
        this.newList = []
      }
    },
    mounted: function () {
      this.getList()
    }
  })
} ())
